package Fragments;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.coolweather.lechat.R;
import com.tencent.imsdk.v2.V2TIMFriendInfo;
import com.tencent.imsdk.v2.V2TIMFriendSearchParam;
import com.tencent.imsdk.v2.V2TIMManager;
import com.tencent.imsdk.v2.V2TIMValueCallback;

import java.util.List;

import activity.SendNews;

public class FragmentContact extends Fragment {
    private static final String TAG = "FragmentContact";
    private ContactAdapter contactAdapter;
    private View view;
    private RecyclerView recyclerView;

    static class ContactAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
        private Context context;

        public ContactAdapter(Context context) {
            this.context = context;
        }

        @NonNull
        @Override
        public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
            View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.chat_item,parent,false);
            return new ContactViewHolder(view);
        }

        @Override
        public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
            ContactViewHolder contactViewHolder =(ContactViewHolder)holder;

            contactViewHolder.item_name.setText("王靓露");
            contactViewHolder.mView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Intent intent = new Intent(context, SendNews.class);
                    context.startActivity(intent);
                }
            });
        }

        @Override
        public int getItemCount() {
            return 1;
        }

        static class ContactViewHolder extends RecyclerView.ViewHolder{

            private ImageView item_img_tou;
            private TextView item_name;
            private View mView;

            public ContactViewHolder(@NonNull View view) {
                super(view);
                item_img_tou =view.findViewById(R.id.item_img_tou);
                item_name = view.findViewById(R.id.item_name);
                mView = view;
            }
        }
    }
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
       view=inflater.inflate(R.layout.fragment_contact,container,false);
       contactAdapter = new ContactAdapter(getActivity());
       initView();
       return view;
    }

    private void initView() {
        recyclerView = view.findViewById(R.id.recyclerView);
        Log.e(TAG, "initView:"+recyclerView);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        recyclerView.setAdapter(contactAdapter);

    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
    }
}
